import 'package:flutter/material.dart';
import 'package:freemusic/model/AbstractSong.dart';
import 'package:freemusic/services/GedanServices.dart';
import 'package:freemusic/utils/Util.dart';

class GedanDialog extends StatefulWidget {
  //要加入歌单的歌曲，如果为空，不添加
  final AbstractSong song;

  const GedanDialog({Key key, this.song}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return GedanDialogState();
  }
}

class GedanDialogState extends State<GedanDialog> {
  String gedanName;

  void handleSaveGedanOnPressed() {
    GedanServices.getInstace().addNewGedan(this.gedanName).then((v) {
      if (v) {
        Navigator.of(context).pop(1);
      }
    });
  }

  void handleTextOnChaged(value) {
    this.gedanName = value;
  }

  @override
  Widget build(BuildContext context) {
    Color themeColor = Util.themeColor;
    return Dialog(
      child: Container(
        padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
        height: 142,
        child: Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(bottom: 20),
              child: Text(
                "新建歌单",
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              height: 32,
              child: TextField(
                decoration: InputDecoration(
                  fillColor: Colors.white,
                  filled: true,
                  hintText: "请输入歌单名称",
                  contentPadding: EdgeInsets.all(5.0),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4.0),
                    borderSide: BorderSide(width: 1, color: themeColor),
                  ),
                ),
                onChanged: this.handleTextOnChaged,
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  MaterialButton(
                    child: Text(
                      "保存",
                      style: TextStyle(color: Util.themeColor),
                    ),
                    onPressed: this.handleSaveGedanOnPressed,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
